import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { RefundService } from '../../services/admin/refund.service';

/**
 * PayRefundController
 * 对应 PHP: PayRefund Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('pay')
@Controller('adminapi/pay')
export class PayRefundController {
  constructor(private readonly refundService: RefundService) {}

  /**
   * 退款管理
   * 路由: GET refund/status
   * PHP路由: Route::get('refund/status', 'pay.PayRefund/getStatus')
   */
  @Get('refund/status')
  @ApiOperation({ summary: '退款管理' })
  async getStatus() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getStatus
      // 直接返回字典数据
      return RefundDict.getStatus();
    } catch (error) {
      throw new BusinessException('getStatus操作失败', error);
    }
  }

  /**
   * 退款管理
   * 路由: GET refund
   * PHP路由: Route::get('refund', 'pay.PayRefund/pages')
   */
  @Get('refund')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '退款管理' })
  async pages(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: pages

      return await this.refundService.getPage(data);
    } catch (error) {
      throw new BusinessException('pages操作失败', error);
    }
  }

  /**
   * 退款管理
   * 路由: GET refund/:refund_no
   * PHP路由: Route::get('refund/:refund_no', 'pay.PayRefund/detail')
   */
  @Get('refund/:refund_no')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '退款管理' })
  async detail(@Param('refund_no') refund_no: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: detail

      return await this.refundService.getDetail(refund_no);
    } catch (error) {
      throw new BusinessException('detail操作失败', error);
    }
  }

  /**
   * 退款管理
   * 路由: GET refund/type
   * PHP路由: Route::get('refund/type', 'pay.PayRefund/getRefundType')
   */
  @Get('refund/type')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '退款管理' })
  async getRefundType(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getRefundType

      return await this.payRefund.getType();
    } catch (error) {
      throw new BusinessException('getRefundType操作失败', error);
    }
  }

  /**
   * 退款管理
   * 路由: POST refund/transfer
   * PHP路由: Route::post('refund/transfer', 'pay.PayRefund/transfer')
   */
  @Post('refund/transfer')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '退款管理' })
  async transfer(@Body() data: TransferDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: transfer

      return await this.refundService.refund(data);
    } catch (error) {
      throw new BusinessException('transfer操作失败', error);
    }
  }
}
